package dao

import (
	"gitee.com/legend9999/publisher/modle"
	"log"
)

type UserDAO int

func (b *UserDAO) Query() ([]*modle.User, error) {
	var book []*modle.User
	if err := DB.Find(&book).Error; err != nil {
		log.Printf("query user err:%s", err)
		return nil, err
	}
	return book, nil
}
func (b *UserDAO) Create(user *modle.User) error {
	if err := DB.Create(user).Error; err != nil {
		log.Printf("create user err:%s", err)
		return err
	}
	return nil
}

func (b *UserDAO) Update(user *modle.User) error {
	if err := DB.Save(user).Error; err != nil {
		log.Printf("update user%+v err:%s", user, err)
		return err
	}
	return nil
}
func (b *UserDAO) QueryByLoginName(loginName string) (*modle.User, error) {
	var book = new(modle.User)
	if err := DB.Where("login_name = ?", loginName).First(book).Error; err != nil {
		log.Printf("query user err:%s", err)
		return nil, err
	}
	return book, nil
}
